package com.itheima.bos.mq;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

@Service("smsConsumer")
public class SmsConsumer implements MessageListener {

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			// 调用Sms服务发送短信
			String result = "000/xxx";
			if (result.startsWith("000")) {
				// 发送成功
				System.out.println("短信发送成功" + mapMessage.getString("telephone")
						+ ",验证码:" + mapMessage.getString("sendSms"));

			} else {
				throw new RuntimeException("短信发送失败,信息码：" + result);
			}
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
